define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'adminlte', 'template'], function ($, undefined, Backend, Table, Form, Adminlte, Template) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'dormitory/exchange/index',
                    add_url: '',
                    edit_url: '',
                    del_url: '',
                    multi_url: '',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                sortName: 'id',
                columns: [
                    [

                        {field: 'state', checkbox: true, },
                        // {
                        //     field: 'c.dorm_number', title: __('寝室'), searchList: function (column) {
                        //         return Template('gardenTpl', {});
                        //     }, formatter: function (value, row, index) {
                        //         return '无';
                        //     }, visible: false
                        // },
                        {field: 'student_number', title: __('学号'), operate: false},
                        {field: 'student_name', title: __('姓名'), operate: false},
                        {field: 'gender_text', title: __('性别'), operate: false},
                        {field: 'old_school_name', title: __('原学校'), operate: false},
                        {field: 'old_garden_name', title: __('原园区'), operate: false},
                        {field: 'old_building_name', title: __('原楼栋'), operate: false},
                        {field: 'old_dorm_number', title: __('原寝室'), operate: false},
                        {field: 'old_bed_num', title: __('原床位'), operate: false},
                        {field: 'new_school_name', title: __('调换学校'), operate: false},
                        {field: 'new_garden_name', title: __('调换园区'), operate: false},
                        {field: 'new_building_name', title: __('调换楼栋'), operate: false},
                        {field: 'new_dorm_number', title: __('调换寝室'), operate: false},
                        {field: 'new_bed_num', title: __('调换床位'), operate: false},
                        {
                            field: 'created_at',
                            title: __('调换时间'),
                            sortable: true,
                            formatter: Table.api.formatter.datetime,
                            operate: 'RANGE',
                            addclass: 'datetimerange'
                        },
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                commonSearch: true,
                searchFormVisible: true,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);

        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {

            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});